package cn.stylefeng.guns.modular.kh.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.kh.entity.KhTzStorageOrder;
import cn.stylefeng.guns.modular.kh.mapper.KhTzStorageOrderMapper;
import cn.stylefeng.guns.modular.kh.model.params.KhTzStorageOrderParam;
import cn.stylefeng.guns.modular.kh.model.result.KhTzStorageOrderResult;
import  cn.stylefeng.guns.modular.kh.service.KhTzStorageOrderService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 提总分拣单 服务实现类
 * </p>
 *
 * @author zzh
 * @since 2025-10-23
 */
@Service
public class KhTzStorageOrderServiceImpl extends ServiceImpl<KhTzStorageOrderMapper, KhTzStorageOrder> implements KhTzStorageOrderService {

    @Override
    public void add(KhTzStorageOrderParam param){
        KhTzStorageOrder entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(KhTzStorageOrderParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(KhTzStorageOrderParam param){
        KhTzStorageOrder oldEntity = getOldEntity(param);
        KhTzStorageOrder newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public KhTzStorageOrderResult findBySpec(KhTzStorageOrderParam param){
        return null;
    }

    @Override
    public List<KhTzStorageOrderResult> findListBySpec(KhTzStorageOrderParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(KhTzStorageOrderParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(KhTzStorageOrderParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private KhTzStorageOrder getOldEntity(KhTzStorageOrderParam param) {
        return this.getById(getKey(param));
    }

    private KhTzStorageOrder getEntity(KhTzStorageOrderParam param) {
        KhTzStorageOrder entity = new KhTzStorageOrder();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
